/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commons.beanutils.DynaBean;

import org.apache.commons.beanutils.BasicDynaBean;
import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.PropertyUtils;

/**
 *
 * @author WangShuai
 */
public class Demo1 {

    public static void main(String[] args) throws Exception{
        //1.DynaBean
        DynaProperty[] beanProperties = new DynaProperty[]{
            new DynaProperty("name", String.class),
            new DynaProperty("votes", Long.class)
        };
        BasicDynaClass politicianClass =
                new BasicDynaClass("politician", BasicDynaBean.class, beanProperties);
        DynaBean politician = politicianClass.newInstance();
        // Set the properties via DynaBean
        politician.set("name", "Tony Blair");
        politician.set("votes", new Long(50000000));
        
        // Set the properties with PropertyUtils
        //        PropertyUtils.setProperty(politician, "name", "John Major");
        //        PropertyUtils.setProperty(politician, "votes", new Long(50000000));
        System.out.println(PropertyUtils.getProperty(politician, "name"));
    }
}
